package com.topvision.common.utils;

import com.topvision.common.enumeration.BaseEnum;

/**
 * @author shengwm
 * @version V0.0.1
 * @Title: EnumUtils
 * @Package com.topvision.common.utils.web
 * @Description: 枚举工具类
 * @date 2017/4/23
 */
public class EnumUtils {

    public final static String OUTPUT_CODE = "code";
    public final static String OUTPUT_NAME = "name";

    public static <T extends Enum<T>> T valueOf(Class<T> enumType,
                                                String name) {
        for (Enum value : enumType.getEnumConstants()) {
            if (value instanceof BaseEnum) {
                BaseEnum labeledEnum = (BaseEnum) value;
                if (labeledEnum.getValue().equals(name)) {
                    return (T) value;
                }
            }
        }
        return null;
    }
}
